package com.atguigu.job;

import com.atguigu.constant.DownLoadFileName;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.io.File;
import java.util.Set;

/**
 * @author zhengkaiyuan
 * @version 1.0
 * @create 2021-06-23 11:48
 */
public class ClearDownLoadJob {

    @Autowired
    private JedisPool jedisPool;
    //清理文件
    public void clearDownLoadFile() {
        //获取当前的所有文件
        Set<String> fileNames =
                jedisPool.getResource().smembers(DownLoadFileName.DATE_DOWN_LOAD_RESOURCES);
        //循环遍历删除文件
        for (String fileName : fileNames) {
            File file = new File(fileName);
            file.delete();
            jedisPool.getResource().srem(DownLoadFileName.DATE_DOWN_LOAD_RESOURCES,fileName);
            System.out.println("删除文件file = " + file);
        }


    }
}
